/**
 * 
 */
package com.ymatou.api.sellerpromotion.testcase;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.hamcrest.core.IsEqual;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.api.marketingseller.service.CreateSellerPromotionCall;
import com.ymatou.api.sellerpromotion.service.GetSellerPromotionInfoByProductIdsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.SellerPromotionCallService;
import com.ymttest.database.mongo.SellerPromotionInfoWapper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;

public class Ts_GetSellerPromotionInfoByProductIds {
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据商品Id集合获取商品促销信息--需完善");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new GetSellerPromotionInfoByProductIdsCall().getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerPromotionInfoByProductIds_001() {
		Logger.start(true, "买手存在进行中的满减促销，查询结果与mongo 一致");
		try {
			int sellerId = 20323743;
			SellerPromotionCallService.checkIsExistPromotion(sellerId);
			
			Map<String,Object> Firstmap = new HashMap<String,Object>();
			Firstmap.put("PromotionInfo->PromotionName","满2件减8.8-自动");
			Firstmap.put("PromotionInfo->PromotionBeginTime",YMTDateUtil.getBeforeOrNextDay(1));
			Firstmap.put("PromotionInfo->PromotionEndTime",YMTDateUtil.getBeforeOrNextDay(3));
			Firstmap.put("PromotionInfo->PromotionType","1");
			Firstmap.put("PromotionInfo->IsSpecifyProduct",true);
			Firstmap.put("PromotionInfo->ProductIds",new JSONArray("[bf92baaa-acb2-4de7-bb2d-792a5322bc02,f0e7200f-2577-4a24-8d3b-45e76f7ab527]"));
			new CreateSellerPromotionCall().callAndGetReturnData(Firstmap);
			
			
			// 促销商品ID
			// 获取mongo 数据
			ArrayList<Map> mongoMap = new SellerPromotionInfoWapper().getPromotions(sellerId);
			boolean IsShowProducts = true;
			JSONObject GetSellerPromotionInfoByProductIdsBean = new GetSellerPromotionInfoByProductIdsCall().callAndGetReturnData(MapUtil.hashMap("sellerId", sellerId,"IsShowProducts",IsShowProducts));
			
			Logger.verifyEquals(200,GetSellerPromotionInfoByProductIdsBean.getInt("Code"), "响应报文-返回码");
			// 校验mongo 数据库数据
			
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerPromotionInfoByProductIds_002() {
		Logger.start(true, "买手不存在正在进行中的促销，查询结果为空");
		try {
			int sellerId = 20323743;
			SellerPromotionCallService.checkIsExistPromotion(sellerId);
			// 促销商品ID
			// 获取mongo 数据
			ArrayList<Map> mongoMap = new SellerPromotionInfoWapper().getPromotions(sellerId);
			//Logger.verifyIsNull(, Description)
			boolean IsShowProducts = true;
			JSONObject GetSellerPromotionInfoByProductIdsBean = new GetSellerPromotionInfoByProductIdsCall().callAndGetReturnData(MapUtil.hashMap("sellerId", sellerId,"IsShowProducts",IsShowProducts));
			
			Logger.verifyEquals(200,GetSellerPromotionInfoByProductIdsBean.getInt("Code"), "响应报文-返回码");
			// 校验mongo 数据库数据
			Logger.verifyIsNull(GetSellerPromotionInfoByProductIdsBean.getJSONObject("Data").getJSONArray("SellerProductsPromotionInfos").getJSONObject(0).getString("ValidPromotionInfos"),"不存在有效促销策略");
			Logger.verifyIsNull(GetSellerPromotionInfoByProductIdsBean.getJSONObject("Data").getJSONArray("SellerProductsPromotionInfos").getJSONObject(0).getString("InvalidPromotionInfos"),"不存在有效促销策略");
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


